<!-- eslint-disable vue/valid-v-slot -->
<template>
  <div class="main-container">
    <TableBody>
      <template #header>
        <TableHeader ref="tableHeaderRef" :show-filter="false">
          <template #search-content>
            <a-form ref="seachRef" :model="seachForm">
              <a-row :gutter="24">
                <a-col :span="4">
                  <a-form-item field="phone" hide-label>
                    <a-input-group>
                      <a-select
                        style="width: 50%"
                        @change="seachTypeChangeFn"
                        v-model="seachType"
                        placeholder="first"
                        :options="seachTypeList"
                      />
                      <a-input
                        style="width: 50%"
                        v-model="seachTypeText"
                        allow-clear
                        placeholder="请输入搜索条件"
                      >
                        <!-- <template #suffix>
                          <icon-plus @click="openTypeMore" style="cursor: pointer" />
                        </template> -->
                      </a-input>
                    </a-input-group>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="type" hide-label>
                    <a-select v-model="seachForm.type" placeholder="请选择海报类型" allow-clear>
                      <a-option :value="0">分享商品</a-option>
                      <a-option :value="1">分享店铺</a-option>
                      <a-option :value="2">邀请注册</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="state" hide-label>
                    <a-select v-model="seachForm.state" placeholder="请选择海报状态" allow-clear>
                      <a-option value="0">正常</a-option>
                      <a-option value="1">关闭</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="addTime" hide-label>
                    <a-date-picker
                      v-model="seachForm.addTime"
                      style="width: 100%"
                      show-time
                      placeholder="请选择开始时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(7, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (seachForm.addTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (seachForm.endTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (seachForm.addTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="endTime" hide-label>
                    <a-date-picker
                      v-model="seachForm.endTime"
                      style="width: 100%"
                      show-time
                      placeholder="请选择结束时间"
                      :time-picker-props="{ defaultValue: '12:00:00' }"
                      format="YYYY-MM-DD HH:mm:ss"
                      allow-clear
                      :shortcuts="[
                        {
                          label: '今日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            ))
                          ),
                        },
                        {
                          label: '昨日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '七日',
                          value: () => (
                            (seachForm.addTime = $dayjs('00:00:00', 'HH:mm:ss')
                              .subtract(7, 'day')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs('23:59:59', 'HH:mm:ss')
                              .subtract(1, 'day')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '本月',
                          value: () => (
                            (seachForm.addTime = $dayjs('01 00:00:00', 'DD HH:mm:ss').format(
                              'YYYY-MM-DD HH:mm:ss'
                            )),
                            (seachForm.endTime = $dayjs().format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                        {
                          label: '上月',
                          value: () => (
                            (seachForm.addTime = $dayjs(`01 00:00:00`, 'DD HH:mm:ss')
                              .subtract(1, 'month')
                              .format('YYYY-MM-DD HH:mm:ss')),
                            (seachForm.endTime = $dayjs()
                              .subtract(1, 'month')
                              .endOf('month')
                              .format('YYYY-MM-DD HH:mm:ss'))
                          ),
                        },
                      ]"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="4">
                  <a-form-item field="btns" hide-label>
                    <a-space :size="15">
                      <a-button type="primary" html-type="submit" @click="doRefresh(1)"
                        ><template #icon>
                          <icon-search />
                        </template>
                        <!-- Use the default slot to avoid extra spaces -->
                        <template #default>搜索</template></a-button
                      >
                      <a-button @click="resetSeach"
                        ><template #icon>
                          <icon-sync theme="outline" size="14" />
                        </template>
                        <!-- Use the default slot to avoid extra spaces -->
                        <template #default>重置</template></a-button
                      >
                    </a-space>
                  </a-form-item>
                </a-col>
              </a-row>
            </a-form>
          </template>
        </TableHeader>
      </template>
      <template #table-config>
        <a-space :size="15">
          <a-button type="primary" @click="addItem">
            <template #default>生成</template>
          </a-button>
        </a-space>
        <a-space :size="15">
          <TableConfig
            @update-border="onUpdateBorder"
            @update-striped="onUpdateStriped"
            @refresh="doRefresh"
          />
        </a-space>
      </template>
      <template #default>
        <a-table
          :bordered="{ wrapper: bordered, cell: bordered }"
          :stripe="(striped as boolean)"
          :loading="tableLoading"
          :data="table.dataList"
          :pagination="false"
          :column-resizable="true"
          :rowKey="rowKey"
          :columns="tableColumns.list"
          :scrollbar="{ type: 'track', outerClass: '', outerStyle: '' }"
          :scroll="{ x: 1500 }"
          table-layout-fixed
        >
          <template #columns>
            <a-table-column
              v-for="item of tableColumns.list"
              :key="item.key"
              align="left"
              :width="item.width"
              :ellipsis="true"
              :tooltip="true"
              :title="(item.title as string)"
              :data-index="(item.key as string)"
              :fixed="item.fixed"
            >
              <template v-if="item.key === 'type'" #cell="{ record }">
                {{ record.type == 0 ? '分享商品' : record.type == 1 ? '分享店铺' : '邀请注册' }}
              </template>
              <template v-if="item.key === 'img'" #cell="{ record }">
                <a-image
                  :src="
                    url +
                    record.type +
                    '&imgUrl=' +
                    record.imgUrl.slice(1) +
                    '&productImgSize=' +
                    record.productImgSize +
                    '&productMarginTop=' +
                    record.productMarginTop +
                    '&productMarginLeft=' +
                    record.productMarginLeft +
                    '&qrCodeSize=' +
                    record.qrCodeSize +
                    '&qrMarginTop=' +
                    record.qrMarginTop +
                    '&qrMarginLeft=' +
                    record.qrMarginLeft
                  "
                  style="height: 70px; width: 80px"
                  alt=""
                />
              </template>
              <template v-if="item.key === 'state'" #cell="{ record }">
                <a-switch
                  size="small"
                  @change="changeState(record)"
                  v-model="record.state"
                  :checked-value="0"
                  :unchecked-value="1"
                />
              </template>
              <template v-else-if="item.key === 'actions'" #cell="{ record }">
                <a-space :size="2">
                  <a-button
                    style="padding: 0px 4px"
                    type="text"
                    @click="updateItem(record)"
                    size="small"
                    >编辑</a-button
                  >
                  <a-button
                    style="padding: 0px 4px"
                    type="text"
                    status="danger"
                    @click="infoDelete(record)"
                    size="small"
                  >
                    删除
                  </a-button>
                </a-space>
              </template>
            </a-table-column>
          </template>
        </a-table>
      </template>
      <template #footer>
        <TableFooter ref="tableFooterRef" :pagination="pagination" />
      </template>
    </TableBody>
    <!-- 多条件搜索 -->
    <a-modal
      v-model:visible="moreVisible"
      @before-close="closeTypeMore"
      title="多条件搜索"
      width="400px"
      :mask-closable="false"
      title-align="start"
    >
      <a-textarea v-model="moreText" placeholder="请输入搜索条件，一行一个" allow-clear />
      <template #footer>
        <a-space>
          <a-button @click="closeTypeMore">取消</a-button>
          <a-button type="primary" @click="conTypeMore">确定</a-button>
        </a-space>
      </template>
    </a-modal>
    <!-- 添加/修改海报 -->
    <a-drawer
      :width="860"
      :title="title"
      @close="closeInfo"
      @ok="confItem"
      @cancel="closeInfo"
      @before-close="closeInfo"
      :visible="infoVisible"
      :mask-closable="false"
    >
      <Scrollbar class="wrapper" style="padding: 20px">
        <a-form ref="infoRef" layout="vertical" :model="infoForm" :auto-label-width="true">
          <a-collapse class="top" v-model:active-key="list1" expand-icon-position="right">
            <a-collapse-item key="1">
              <template #header>
                <div class="box">
                  <div class="line"></div>
                  <div class="text">海报信息</div>
                </div>
              </template>
              <template #extra>
                <div>{{ list1.length == 1 ? '收起' : '展开' }}</div>
              </template>
              <a-space wrap :size="20" align="start" style="margin-left: 4px; width: 840px">
                <a-form-item
                  label="海报名称"
                  field="name"
                  class="input516"
                  :rules="[{ required: true, message: '请输入海报名称' }]"
                  asterisk-position="end"
                >
                  <a-input placeholder="请输入海报名称" v-model.trim="infoForm.name" />
                </a-form-item>
                <a-form-item
                  class="input516"
                  field="type"
                  label="海报类型"
                  :rules="[{ required: true, message: '请选择套餐类型' }]"
                  asterisk-position="end"
                >
                  <a-radio-group class="radio-bcg" @change="changeType" v-model="infoForm.type">
                    <a-radio :value="0">
                      <template #radio="{ checked }">
                        <div
                          style="display: flex"
                          :class="{ 'custom-radio-card-checked': checked }"
                        >
                          <div className="custom-radio-card-mask">
                            <div className="custom-radio-card-mask-dot"></div> </div
                          ><div className="custom-radio-card-title">分享商品</div>
                        </div>
                      </template>
                    </a-radio>
                    <a-radio :value="1">
                      <template #radio="{ checked }">
                        <div
                          style="display: flex"
                          :class="{ 'custom-radio-card-checked': checked }"
                        >
                          <div className="custom-radio-card-mask">
                            <div className="custom-radio-card-mask-dot"></div> </div
                          ><div className="custom-radio-card-title">分享店铺</div>
                        </div>
                      </template>
                    </a-radio>
                    <a-radio :value="2">
                      <template #radio="{ checked }">
                        <div
                          style="display: flex"
                          :class="{ 'custom-radio-card-checked': checked }"
                        >
                          <div className="custom-radio-card-mask">
                            <div className="custom-radio-card-mask-dot"></div> </div
                          ><div className="custom-radio-card-title">邀请注册</div>
                        </div>
                      </template>
                    </a-radio>
                  </a-radio-group>
                </a-form-item>
                <a-form-item
                  label="海报图片"
                  field="imgUrl"
                  class="input516"
                  :rules="[{ required: true, message: '请上传图片' }]"
                  asterisk-position="end"
                >
                  <a-upload
                    action="/app/file/upload"
                    :show-file-list="false"
                    @success="onSuccessLogo"
                    :image-preview="true"
                  >
                    <template #upload-button>
                      <div
                        class="arco-upload-list-picture custom-upload-avatar"
                        v-if="infoForm.imgUrl"
                      >
                        <img :src="infoForm.imgUrl" />
                        <div class="arco-upload-list-picture-mask">
                          <IconEdit />
                        </div>
                      </div>
                      <div class="arco-upload-picture-card" v-else>
                        <div class="arco-upload-picture-card-text">
                          <IconPlus />
                        </div>
                      </div>
                      <!-- </div> -->
                    </template>
                  </a-upload>
                </a-form-item>

                <a-form-item label="海报备注" field="remark" class="input516">
                  <a-input placeholder="请输入海报备注" v-model.trim="infoForm.remark" />
                </a-form-item>
              </a-space>
            </a-collapse-item>
          </a-collapse>
          <a-collapse class="top" v-model:active-key="list2" expand-icon-position="right">
            <a-collapse-item key="1">
              <template #header>
                <div class="box">
                  <div class="line"></div>
                  <div class="text">海报设置</div>
                </div>
              </template>
              <template #extra>
                <div>{{ list2.length == 1 ? '收起' : '展开' }}</div>
              </template>
              <a-space wrap :size="20" align="start" style="margin-left: 4px; width: 840px">
                <a-space wrap :size="20" style="width: 420px">
                  <a-form-item
                    class="input200"
                    field="defaults"
                    label="默认海报"
                    asterisk-position="end"
                  >
                    <a-radio-group class="radio-bcg" v-model="infoForm.defaults">
                      <a-radio :value="0">
                        <template #radio="{ checked }">
                          <div
                            style="display: flex"
                            :class="{ 'custom-radio-card-checked': checked }"
                          >
                            <div className="custom-radio-card-mask">
                              <div className="custom-radio-card-mask-dot"></div> </div
                            ><div className="custom-radio-card-title">开启</div>
                          </div>
                        </template>
                      </a-radio>
                      <a-radio :value="1">
                        <template #radio="{ checked }">
                          <div
                            style="display: flex"
                            :class="{ 'custom-radio-card-checked': checked }"
                          >
                            <div className="custom-radio-card-mask">
                              <div className="custom-radio-card-mask-dot"></div> </div
                            ><div className="custom-radio-card-title">关闭</div>
                          </div>
                        </template>
                      </a-radio>
                    </a-radio-group>
                  </a-form-item>
                  <a-form-item
                    v-if="infoForm.type === 0"
                    label="商品图片尺寸"
                    field="productImgSize"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input-number
                      placeholder="请输入二维码尺寸"
                      v-model.trim="infoForm.productImgSize"
                    />
                  </a-form-item>
                  <a-form-item
                    v-if="infoForm.type === 0"
                    label="上移"
                    field="productMarginTop"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input
                      placeholder="请输入二维码尺寸"
                      v-model.trim="infoForm.productMarginTop"
                    />
                  </a-form-item>
                  <a-form-item
                    v-if="infoForm.type === 0"
                    label="左移"
                    field="productMarginLeft"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input
                      placeholder="请输入二维码尺寸"
                      v-model.trim="infoForm.productMarginLeft"
                    />
                  </a-form-item>
                  <a-form-item
                    label="二维码尺寸"
                    field="qrCodeSize"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input-number
                      placeholder="请输入二维码尺寸"
                      v-model.trim="infoForm.qrCodeSize"
                    />
                  </a-form-item>
                  <a-form-item
                    label="上移"
                    field="qrMarginTop"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input placeholder="请输入二维码尺寸" v-model.trim="infoForm.qrMarginTop" />
                  </a-form-item>
                  <a-form-item
                    label="左移"
                    field="qrMarginLeft"
                    class="input200"
                    :rules="[{ required: true, message: '请输入二维码尺寸' }]"
                    asterisk-position="end"
                  >
                    <a-input placeholder="请输入二维码尺寸" v-model.trim="infoForm.qrMarginLeft" />
                  </a-form-item>
                </a-space>
                <div>
                  <a-form-item
                    label="海报预览"
                    field="name"
                    class="input516"
                    style="margin-left: -20px"
                  >
                    <div
                      style="
                        width: 100%;
                        border: 1px solid #f2f3f5;
                        padding: 10px;
                        box-sizing: border-box;
                      "
                    >
                      <div style="width: 380px; height: 100%; position: relative">
                        <a-image
                          v-if="infoForm.imgUrl"
                          style="height: 100%; z-index: 10"
                          :src="
                            url +
                            infoForm.type +
                            '&imgUrl=' +
                            infoForm.imgUrl +
                            '&productImgSize=' +
                            infoForm.productImgSize +
                            '&productMarginTop=' +
                            infoForm.productMarginTop +
                            '&productMarginLeft=' +
                            infoForm.productMarginLeft +
                            '&qrCodeSize=' +
                            infoForm.qrCodeSize +
                            '&qrMarginTop=' +
                            infoForm.qrMarginTop +
                            '&qrMarginLeft=' +
                            infoForm.qrMarginLeft
                          "
                          show-loader
                        />
                      </div>
                    </div>
                  </a-form-item>
                </div>
              </a-space>
            </a-collapse-item>
          </a-collapse>
        </a-form>
      </Scrollbar>
      <template #footer>
        <a-space>
          <a-button @click="closeInfo">取消</a-button>
          <a-button type="primary" @click="confItem">确定</a-button>
        </a-space>
      </template>
    </a-drawer>
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive, onMounted } from 'vue'
  import { posterList, posterAdd, posterUpdate, posterDelete, posterState } from '@/api/user'
  import { get, post } from '@/api/http'
  import { usePagination, useRowKey, useTable } from '@/hooks/table'
  import { Message, Modal } from '@arco-design/web-vue'

  const pagination = usePagination(doRefresh)
  const table = useTable()
  const rowKey = useRowKey('id')
  const bordered = ref(false)
  const striped = ref(false)
  const tableLoading = ref(true)
  const tableColumns: any = reactive({
    list: [
      {
        title: '海报ID',
        key: 'id',
        dataIndex: 'id',
        ellipsis: true,
        tooltip: true,
        checked: true,
        width: 129,
      },
      {
        title: '海报名称',
        key: 'name',
        dataIndex: 'name',
        ellipsis: true,
        tooltip: true,
        checked: true,
        width: 234,
      },
      {
        title: '海报类型',
        key: 'type',
        dataIndex: 'type',
        checked: true,
        width: 158,
      },
      {
        title: '海报图片',
        key: 'img',
        dataIndex: 'img',
        checked: true,
        width: 158,
      },
      {
        title: '海报状态',
        key: 'state',
        dataIndex: 'state',
        checked: true,
        width: 160,
      },
      {
        title: '海报备注',
        key: 'remark',
        dataIndex: 'remark',
        checked: true,
        width: 160,
      },
      {
        title: '生成时间',
        key: 'addTime',
        dataIndex: 'addTime',
        width: 232,
        checked: true,
      },
      {
        title: '操作',
        key: 'actions',
        fixed: 'right',
        dataIndex: 'actions',
        width: 180,
        align: 'center',
        checked: true,
      },
    ],
  })
  //搜索项
  const seachRef = ref()
  const seachType = ref('name')
  const seachTypeText = ref('')
  const seachTypeList = ref([
    {
      value: 'id',
      label: '海报ID',
    },
    {
      value: 'name',
      label: '海报名称',
    },
  ])
  const seachForm = ref({
    id: '', //     id
    name: '', //     名称
    type: '', //     类型 0分享商品 1分享店铺 2邀请注册
    state: '', //    状态 0正常 1关闭
    addTime: '', //  开始时间
    endTime: '', //  结束时间
  })
  //多条件搜索
  const moreVisible = ref(false)
  const moreText = ref('')
  //详情
  const url = ref(
    window.location.protocol + '//' + window.location.host + '/app/poster/preview?type='
  )
  const infoVisible = ref(false)
  const infoForm: any = ref({
    name: '', // 海报名称
    type: 0, // 0分享商品 1分享店铺 2邀请注册
    imgUrl: '', // 海报图片地址
    productImgSize: '', // 商品图片尺寸
    productMarginTop: '', //  商品图上边距
    productMarginLeft: '', // 商品图左边距
    qrCodeSize: '', // 二维码尺寸
    qrMarginTop: '', // 二维码上边距
    qrMarginLeft: '', // 二维码左边距
    state: '', // 海报状态 0正常 1关闭
    defaults: 0, // 默认海报 0默认 1非默认，一个类型只能有一个默认
    remark: '', // 备注
  })
  const title = ref('生成海报')
  const infoRef = ref()
  //折叠
  const list1 = ref(['1'])
  const list2 = ref(['1'])
  //搜索类型切换
  function seachTypeChangeFn() {
    seachForm.value.id = ''
    seachForm.value.name = ''
  }
  //打开多项搜索
  function openTypeMore() {
    moreVisible.value = true
  }
  //确认多条件
  function conTypeMore() {
    const arr = moreText.value.split(/\n/g)
    seachTypeText.value = arr.toString()
    closeTypeMore()
  }
  //关闭多条件搜索回调
  function closeTypeMore() {
    moreVisible.value = false
  }
  //重置搜索项
  function resetSeach() {
    seachForm.value.id = ''
    seachForm.value.name = ''
    seachTypeText.value = ''
    seachRef.value.resetFields()
    doRefresh(1)
  }
  //弹窗关闭回调
  function closeInfo() {
    infoRef.value.resetFields()
    infoForm.value.productImgSize = ''
    infoForm.value.productMarginTop = '' //  商品图上边距
    infoForm.value.productMarginLeft = '' // 商品图左边距
    infoVisible.value = false
  }
  function infoDelete(val: any) {
    Modal.warning({
      title: '操作提示',
      titleAlign: 'start',
      content: '确定要删除此海报？',
      hideCancel: false,
      onOk() {
        get({
          url: posterDelete,
          data: {
            id: val.id,
          },
        }).then((res) => {
          if (res.code == 0) {
            Message.success(res.msg)
            doRefresh()
          }
        })
      },
    })
  }
  function changeState(item: any) {
    onChangeItem(item)
  }

  function onChangeItem(item: any) {
    Modal.warning({
      title: '操作提示',
      titleAlign: 'start',
      content: '确定要更改海报状态？',
      hideCancel: false,
      onOk() {
        changeGoodsState(item)
      },
    })
  }
  //修改状态
  function changeGoodsState(val: any) {
    get({
      url: posterState,
      data: {
        id: val.id,
        state: val.state,
      },
    }).then((res) => {
      if (res.code == 0) {
        Message.success(res.msg)
        doRefresh()
      }
    })
  }
  //添加海报
  function addItem() {
    title.value = '生成海报'
    infoForm.value.id = null
    infoVisible.value = true
  }

  //修改海报
  function updateItem(val: any) {
    if (!val.productImgSize) {
      val.productImgSize = ''
      val.productMarginTop = '' //  商品图上边距
      val.productMarginLeft = '' // 商品图左边距
    }
    title.value = '修改海报'
    infoForm.value = JSON.parse(JSON.stringify(val))
    infoVisible.value = true
  }

  //添加/修改海报
  function confItem() {
    infoRef.value?.validate().then((error: any) => {
      if (!error) {
        if (!infoForm.value.id) {
          post({
            url: posterAdd,
            data: () => {
              return {
                ...infoForm.value,
              }
            },
          })
            .then((res) => {
              Message.success(res.msg)
              closeInfo()
              doRefresh()
            })
            .catch(console.log)
        } else {
          post({
            url: posterUpdate,
            data: () => {
              return {
                ...infoForm.value,
              }
            },
          })
            .then((res) => {
              Message.success(res.msg)
              closeInfo()
              doRefresh()
            })
            .catch(console.log)
        }
      }
    })
  }
  //海报类型切换
  function changeType(val: any) {
    if (val == 1 || val == 2) {
      infoForm.value.productImgSize = ''
      infoForm.value.productMarginTop = '' //  商品图上边距
      infoForm.value.productMarginLeft = '' // 商品图左边距
    }
  }
  const activeTag = ref('')
  //Logo上传
  const onSuccessLogo = (fileItem: any) => {
    infoForm.value.imgUrl = fileItem.response.data.path
    console.log(infoForm.value.imgUrl, fileItem.response.data)
    infoForm.value.qrCodeSize = 200
    infoForm.value.qrMarginTop = 150
    infoForm.value.qrMarginLeft = 150
    if (infoForm.value.type == 0) {
      infoForm.value.productImgSize = 200
      infoForm.value.productMarginTop = 180
      infoForm.value.productMarginLeft = 180
    }
  }
  //获取列表
  function doRefresh(page?: any) {
    if (page) {
      pagination.page = page
    }
    seachForm.value[seachType.value] = seachTypeText.value
    get({
      url: posterList,
      data: () => {
        return {
          page: pagination.page,
          size: pagination.pageSize,
          ...seachForm.value,
        }
      },
    })
      .then((res) => {
        res.data.list.forEach((element: any) => {
          if (!element.productImgSize) {
            element.productImgSize = ''
            element.productMarginTop = '' //  商品图上边距
            element.productMarginLeft = '' // 商品图左边距
          }
        })
        tableLoading.value = false
        table.handleSuccess(res.data.list)
        pagination.setTotalSize((res.data as any).totalSize)
      })
      .catch(console.log)
  }
  function onUpdateBorder(isBordered: boolean) {
    bordered.value = isBordered
  }
  function onUpdateStriped(isStriped: boolean) {
    striped.value = isStriped
  }
  onMounted(() => {
    doRefresh(1)
  })
</script>

<style lang="less" scoped>
  .imgssd {
    top: v-bind('infoForm.qrMarginTop');
    left: v-bind('infoForm.qrMarginLeft');
  }
  .imageBox {
    width: 70px;
    height: 70px;
    cursor: pointer;
    .showImage {
      width: 100%;
      height: 100%;
      display: block;
    }
    .chooseImageBtns {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: #f2f3f5;
      border-radius: 4px;
    }
    .chooseImageBtns:hover {
      background-color: #dbdcde;
    }
  }
  .arco-space-item {
    .arco-form-item {
      margin-bottom: 0 !important;
    }
  }
  .input516 {
    width: 400px;
  }
  .input200 {
    width: 190px;
    margin-bottom: 20px;
  }
  :deep(.arco-collapse-item-header-right + .arco-collapse-item-content) {
    padding-left: 0px !important;
  }
  :deep(.arco-collapse-item-content) {
    padding-right: 0px !important;
    background-color: #fff;
  }
  :deep(.arco-collapse) {
    border: 0 !important;
  }

  :deep(.arco-collapse-item-header) {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-left: 4px;
    margin-top: 8px;
    background-color: var(--color-bg-3);
  }
  :deep(.arco-collapse-item-content-box) {
    background-color: var(--color-bg-3);
  }

  :deep(.arco-collapse-item-active > .arco-collapse-item-header) {
    border: 0 !important;
  }

  :deep(.arco-collapse-item-header-right) {
    padding-left: 0 !important;
    transition: none;
  }
  .box {
    display: flex;
    align-items: center;
    height: 15px;

    .line {
      width: 5px;
      height: 15px;
      margin-right: 10px;
      background-color: #40a1ff;
    }
  }
</style>
